home *** CD-ROM | disk | FTP | other *** search
/ New Star Software Collection / NSS_Collection.iso / 3-004 ms visual basic pro 30 / 4.imz / 4.IMA / ICONWRKS.BA_ / ICONWRKS.bin
Text File  |  1993-04-28  |  35KB  |  925 lines

  1. DefInt A-Z
  2. Dim HelpFilePath As String
  3.  
  4. ' When either the Editor's colorpalette or the ColorPalette Forms
  5. ' ColorPalette need repainting, this routine is called, passing in
  6. ' the picture control used for the specific colorpalette.
  7. '
  8. Sub Display_Color_Palette (Pic_ColorPalette As Control)
  9.     
  10.     ' The ColorPalettes consist of 3 rows of 16 colors, so to make
  11.     ' is easy to display and to deterine what color is selected when
  12.     ' the ColorPalette is click, we set the Scale of the ColorPalette
  13.     ' to correspond to the number of color rows and columns.
  14.     '
  15.     Pic_ColorPalette.Scale (0, 0)-(16, 3)
  16.  
  17.     ' Display ColorPalette column by column
  18.     '
  19.     For I = 0 To 15
  20.         '
  21.         ' Display a column of colors
  22.         '
  23.         Pic_ColorPalette.Line (I, 0)-(I + 1, 1), Colors(I), BF
  24.         Pic_ColorPalette.Line (I, 1)-(I + 1, 2), Colors(I + 16), BF
  25.         Pic_ColorPalette.Line (I, 2)-(I + 1, 3), Colors(I + 32), BF
  26.  
  27.         ' Display vertical line to left of current columns to visually
  28.         ' divide the columns, but skip first column, since it is not
  29.         ' needed due to the Border of the color palette.
  30.         '
  31.         If I Then Pic_ColorPalette.Line (I, 0)-(I, 3)
  32.     Next I
  33.   
  34.     ' Display 2 horizontal lines to visually divide the color rows.
  35.     '
  36.     Pic_ColorPalette.Line (0, 1)-(16, 1)
  37.     Pic_ColorPalette.Line (0, 2)-(16, 2)
  38.  
  39. End Sub
  40.  
  41. ' Displays the entire or any portion of the grid, when the Grid option
  42. ' is active.  The 4 paramaters passed in, X1, Y1, X2, Y2, define the
  43. ' upper left and lower right corners of the area within the maginified
  44. ' Icon that needs the grid displayed.
  45. '
  46. Sub Display_Grid (DestHdc, X1, Y1, X2, Y2)
  47.   
  48.     ' The grid is not displayed if the icon is being viewed at normal
  49.     ' size, so check the current value of the scrollbar.
  50.     '
  51.     If editor.Scrl_Zoom.Value > editor.Scrl_Zoom.Min Then
  52.         DestX = X1 * PixelSize
  53.         DestY = Y1 * PixelSize
  54.         DestWidth = (X2 - X1 + 1) * PixelSize
  55.         DestHeight = (Y2 - Y1 + 1) * PixelSize
  56.         R = BitBlt(DestHdc, X1 * PixelSize, Y1 * PixelSize, DestWidth, DestHeight, editor.Pic_Grid.hDC, DestX, DestY, SRCAND)
  57.     End If
  58.  
  59. End Sub
  60.  
  61. ' Whenever a new color is selected for either the left or right mouse
  62. ' button, or the StatusArea needs repainting, this routine is called to
  63. ' display the 4 small color squares at the bottom of the StatusArea
  64. ' which are filled with the current colors selected for the mouse buttons.
  65. '
  66. Sub Display_Mouse_Colors ()
  67.  
  68.     ' Calculate the center of the Status bar
  69.     '
  70.     Middle = editor.Pic_StatusArea.ScaleWidth \ 2
  71.  
  72.     ' Display the 4 color squares
  73.     '
  74.     For I = 0 To 3
  75.         '
  76.         ' The squares are centered within the left and right halfs of the
  77.         ' StatusArea, and the width and height are set equal to the Height
  78.         ' of the Option buttons used to select Left/Right or Screen/Inverse
  79.         ' colors, so we calculate the corners of the the Color squares
  80.         ' based on this information.
  81.         '
  82.         X1 = (I Mod 2) * Middle + (Middle - editor.Opt_Mouse(I \ 2).Height) \ 2
  83.         X2 = X1 + editor.Opt_Mouse(I \ 2).Height
  84.         Y1 = editor.Opt_Mouse(I \ 2).Top
  85.         Y2 = Y1 + editor.Opt_Mouse(I \ 2).Height
  86.  
  87.         ' Draw the color square
  88.         '
  89.         editor.Pic_StatusArea.Line (X1, Y1)-(X2, Y2), MouseColors(I), BF
  90.  
  91.         ' Draw a black outline around the square
  92.         '
  93.         editor.Pic_StatusArea.Line (X1, Y1)-(X2, Y2), BLACK, B
  94.     Next I
  95.         
  96.     ' Set the CurrentY value of the StatusArea back to that of the
  97.     ' location where the Mouse Coordinates are displayed, so this
  98.     ' does not have to be done within each MouseMove event of the
  99.     ' Edit area.
  100.     '
  101.     editor.Pic_StatusArea.CurrentY = editor.Pic_Icons(5).Top + editor.Pic_Icons(5).Height + HIGHLIGHT + 1
  102.  
  103. End Sub
  104.  
  105. ' If a selection has been made, is being made, or a selection is
  106. ' being moved, or the Edit area needs repainting while a selection
  107. ' is active, this routine is called to display or redisplay a
  108. ' rectangle around the current selection.
  109. '
  110. Sub Draw_Selection_Rectangle ()
  111.  
  112.     ' Set drawing mode to INVERSE since this routine also used to erase
  113.     ' the selection rectangle by simply drawing over the currently displayed
  114.     ' rectangle
  115.     '
  116.     editor.Pic_Edit.DrawMode = Inverse
  117.  
  118.     ' To distinguish between a selection and a selection that is
  119.     ' being moved, a Dotted line is used for a selection and a solid
  120.     ' line is used for a selection being moved.
  121.     '
  122.     If MovingSelection Then editor.Pic_Edit.DrawStyle = SOLID Else editor.Pic_Edit.DrawStyle = DOT
  123.  
  124.     ' To ensure the entire selection rectangle is visible, the rectangle
  125.     ' is adjusted inward 1 pixel from the right and bottom if the selection
  126.     ' contains either the right most column or bottom most row of pixels.
  127.     '
  128.     If X2Region >= PixelSize * 32 Then XAdjust = 1
  129.     If Y2Region >= PixelSize * 32 Then YAdjust = 1
  130.  
  131.     ' Draw the selection rectangle.
  132.     '
  133.     editor.Pic_Edit.Line (X1Region, Y1Region)-(X2Region - XAdjust, Y2Region - YAdjust), , B
  134.     editor.Pic_Edit.DrawStyle = SOLID
  135.  
  136. End Sub
  137.  
  138. ' When the currently selected Icon is changed or a new Icon is
  139. ' loaded into the currently selected Icon, the bitmaps that make
  140. ' of the Icons Mask and Image must be extracted and placed into
  141. ' picture controls where they can easily be edited.
  142. '
  143. Sub Extract_Image_And_Mask (Pic_Ctrl As Control)
  144. Dim Lpicon As Long
  145.     
  146.     ' Get pointer to Icon and prevent Windows form moving it.
  147.     '
  148.     Lpicon = GlobalLock(Pic_Ctrl.Picture)
  149.  
  150.     ' Copy the Icons Mask to Monochrome Bitmap, then copy the MonoBitmap
  151.     ' the the Picture control.
  152.     '
  153.     editor.Pic_Mask.ForeColor = BLACK
  154.     R = SetBitmapBits(MonoHbm, 128, Lpicon + 12)
  155.     R = BitBlt(editor.Pic_Mask.hDC, 0, 0, 32, 32, MonoHdc, 0, 0, SRCCOPY)
  156.  
  157.     ' Copy Icons Image bitmap to Picture control
  158.     '
  159.     R = SetBitmapBits(editor.Pic_Image.Image, ImageSize, Lpicon + 12 + 128)
  160.  
  161.     ' Free icon so Windows is free to move it.
  162.     '
  163.     R = GlobalUnlock(Pic_Ctrl.Picture)
  164.  
  165. End Sub
  166.  
  167. ' Displays the selected help topic selected from either
  168. ' Editors;' or Viewer's help menu.
  169. '
  170. Sub Get_Help (HelpTopic As Integer)
  171.   
  172.     If HelpTopic = MID_USING_HELP Then
  173.         '
  174.         ' "Using Help" was selected so display the Standard Windows Help
  175.         ' Topic for "Using Help".
  176.         '
  177.         R = WinHelp(editor.hWnd, Dummy$, HELP_HELPONHELP, 0)
  178.     Else
  179.         ' A help topic other the "Using help" was selected.
  180.         '
  181.         
  182.         R = WinHelp(editor.hWnd, HelpFilePath, HELP_CONTEXT, CLng(HelpTopic))
  183.     End If
  184.  
  185. End Sub
  186.  
  187. Function Help_File_In_Path ()
  188. Dim Path As String, CurrentDir As String
  189.  
  190.     On Error Resume Next
  191.     CurrentDir = App.Path
  192.     If Right$(CurrentDir, 1) <> "\" Then CurrentDir = CurrentDir + "\"
  193.     Found = Dir$(CurrentDir + "IconWrks.HLP") <> ""
  194.     If Not Found Then
  195.         Path = Environ$("PATH")
  196.         If Path <> "" Then
  197.             If Right$(Path, 1) <> ";" Then Path = Path + ";"
  198.             SemiColon = InStr(Path, ";")
  199.             Do
  200.                 CurrentDir = Left$(Path, SemiColon - 1)
  201.                 If Right$(CurrentDir, 1) <> "\" Then CurrentDir = CurrentDir + "\"
  202.                 Found = Dir$(CurrentDir + "IconWrks.HLP") <> ""
  203.                 Path = Right$(Path, Len(Path) - SemiColon)
  204.                 SemiColon = InStr(Path, ";")
  205.             Loop While ((SemiColon <> 0) And Not Found)
  206.         End If
  207.     End If
  208.     If Found Then
  209.         HelpFilePath = CurrentDir + "IconWrks.HLP"
  210.         App.HelpFile = CurrentDir + "IconWrks.HLP"
  211.     End If
  212.     Help_File_In_Path = Found
  213.     
  214.     On Error GoTo 0
  215.  
  216. End Function
  217.  
  218. ' The currently selected icon is distinguished by a solid square
  219. ' slightly larger than the icon itself, drawn behind the icon using
  220. ' the currently selected screen color.  This routine is called
  221. ' whenever this square needs to be displayed or redisplayed.
  222. '
  223. Sub HighLight_Current_Icon ()
  224.   
  225.     ' Erase the current selection square.
  226.     '
  227.     editor.Pic_StatusArea.Line (0, 0)-(editor.Pic_StatusArea.Width, editor.Pic_Icons(4).Top + editor.Pic_Icons(4).Height + 10), editor.Pic_StatusArea.BackColor, BF
  228.  
  229.     ' Calculate the upper left and lower right corners of the selection square.
  230.     '
  231.     X1 = editor.Pic_Icons(CurrentIcon).Left - HIGHLIGHT
  232.     X2 = editor.Pic_Icons(CurrentIcon).Left + editor.Pic_Icons(CurrentIcon).Width + HIGHLIGHT
  233.     Y1 = editor.Pic_Icons(CurrentIcon).Top - HIGHLIGHT
  234.     Y2 = editor.Pic_Icons(CurrentIcon).Top + editor.Pic_Icons(CurrentIcon).Height + HIGHLIGHT
  235.   
  236.     ' Draw the solid selection square.
  237.     '
  238.     editor.Pic_StatusArea.Line (X1, Y1)-(X2, Y2), MouseColors(2), BF
  239.  
  240.     ' Draw a Black outline around the square.
  241.     '
  242.     editor.Pic_StatusArea.Line (X1, Y1)-(X2, Y2), BLACK, B
  243.  
  244.     If editor.Menu_ViewSelection(MID_BORDER).Checked Then
  245.         '
  246.         ' Show edge of selected Icon by outline the icon
  247.         '
  248.         X1 = editor.Pic_Icons(CurrentIcon).Left - 1
  249.         X2 = editor.Pic_Icons(CurrentIcon).Left + editor.Pic_Icons(CurrentIcon).Width
  250.         Y1 = editor.Pic_Icons(CurrentIcon).Top - 1
  251.         Y2 = editor.Pic_Icons(CurrentIcon).Top + editor.Pic_Icons(CurrentIcon).Height
  252.         editor.Pic_StatusArea.Line (X1, Y1)-(X2, Y2), BLACK, B
  253.     End If
  254.     
  255.     ' Set the CurrentY value of the StatusArea back to that of the
  256.     ' location where the Mouse Coordinates are displayed.
  257.     '
  258.     editor.Pic_StatusArea.CurrentY = editor.Pic_Icons(5).Top + editor.Pic_Icons(5).Height + HIGHLIGHT + 1
  259.     
  260. End Sub
  261.  
  262. ' Inverts the specified control when an Icon from the Viewer is being
  263. ' dragged over the top of it, signaling that the Icon may be dropped
  264. ' on this control.
  265. '
  266. Sub Invert_Control (Ctrl As Control)
  267. Dim rectangle As RECT
  268.   
  269.     ' Calculate the Rectangle to invert
  270.     '
  271.     rectangle.Right = Ctrl.ScaleWidth
  272.     rectangle.bottom = Ctrl.ScaleHeight
  273.  
  274.     ' Invert the rectangle
  275.     '
  276.     R = InvertRect(Ctrl.hDC, rectangle)
  277.  
  278. End Sub
  279.  
  280. ' This routine is used to tie the Viewer and the Editor together.  When
  281. ' and Icon is selected in one of the various ways from within the Viewer,
  282. ' or an Icon is dragged from the Viewer and dropped on a valid location
  283. ' of the Editor, this routine is called either from the Viewer or from
  284. ' the Editor (depending on how the Icon was selected), to load the
  285. ' selected icon into the Editor.
  286. '
  287. Sub Load_An_Icon ()
  288.  
  289.     ' Check if the new icon would be replacing an existing Icon which
  290.     ' has been changed since the last time it has been saved, and if
  291.     ' so, ask the user if it is ok to discard the changes.
  292.     '
  293.     If Ok_To_Discard_Changes() Then
  294.         '
  295.         ' Get the Filename and Fullpath to the icon, and set its
  296.         ' Changed flag to FALSE.
  297.         '
  298.         IconInfo(CurrentIcon).FileName = Viewer.File_FileList.FileName
  299.         IconInfo(CurrentIcon).FullPath = Viewer.File_FileList.Path
  300.         IconInfo(CurrentIcon).Changed = False
  301.  
  302.         ' Place the Name and Path of the Icon in the corresponding menu
  303.         ' item in the Editors Icons menu.
  304.         '
  305.         editor.Menu_IconsSelection(CurrentIcon).Caption = "&" + Format$(CurrentIcon + 1) + " - [" + Viewer.File_FileList.Path + "]" + A_TAB + Viewer.File_FileList.FileName
  306.  
  307.         ' Load the Icon into the selected icon in the StatusArea.
  308.         '
  309.         editor.Pic_Icons(CurrentIcon).Picture = LoadPicture(Viewer.File_FileList.FileName)
  310.  
  311.         ' If the Menu option is set, bring the Editor to the Foreground
  312.         ' when an Icon is loaded.
  313.         '
  314.         If editor.Menu_ViewSelection(MID_FOCUS).Checked Then editor.Show
  315.  
  316.         ' Simulate clicking the Icon in the StatusArea to take care of the
  317.         ' visual part of selection.
  318.         '
  319.         Select_New_Icon
  320.         editor.Pic_ToolPalette.Refresh
  321.     Else
  322.         ' Do not discard the changes of the existing icon.
  323.         '
  324.         editor.Pic_Icons(CurrentIcon).Cls
  325.         Magnify_Icon 0, 0, 31, 31
  326.     End If
  327.  
  328. End Sub
  329.  
  330. ' There are various situations when all or part of the current icon
  331. ' needs to be magnified and displayed in the editing area.  this
  332. ' routine is called to perform the magnification.  The Windows API
  333. ' routine, StretchBlt() is used to perform the magnification.
  334. '
  335. Sub Magnify_Icon (X1, Y1, X2, Y2)
  336.     
  337.     ' Ensure that X1 and Y1 refer to the upper left corner and X2 and Y2
  338.     ' refer to the lower right corner of the area to be magnified.
  339.     '
  340.     If X1 > X2 Then Swap_Values X1, X2
  341.     If Y1 > Y2 Then Swap_Values Y1, Y2
  342.  
  343.     ' The area to be magnified must not contain any pixels outside
  344.     ' of the Icon itself, so we must check for this situation and
  345.     ' adjust the values if neccessary.
  346.     '
  347.     If X1 < 0 Then X1 = 0
  348.     If X2 > 31 Then X2 = 31
  349.     If Y1 < 0 Then Y1 = 0
  350.     If Y2 > 31 Then Y2 = 31
  351.  
  352.     ' Calculate the width and height values of the source bitmap
  353.     '
  354.     SrcWidth = X2 - X1 + 1
  355.     SrcHeight = Y2 - Y1 + 1
  356.  
  357.     ' Calculate the destinations width, height and upper left corner
  358.     ' of the area to be magnified.
  359.     '
  360.     DestX = X1 * PixelSize
  361.     DestY = Y1 * PixelSize
  362.     DestWidth = SrcWidth * PixelSize
  363.     DestHeight = SrcHeight * PixelSize
  364.   
  365.     ' Magnify the icon.  We StretchBlt() from the image of the Icon in
  366.     ' the StatusArea to the Editing area.  Since we always maintain the
  367.     ' size of the Editing area a multiple of 32 (Size of an Icon), the
  368.     ' magnified icon will always be a perfect enlargement of the Icons
  369.     ' image.
  370.     '
  371.     If ImageSize = 1024 Then
  372.         '
  373.         R = StretchBlt(editor.Pic_Edit.hDC, DestX, DestY, DestWidth, DestHeight, editor.Pic_Icons(CurrentIcon).hDC, X1, Y1, SrcWidth, SrcHeight, SRCCOPY)
  374.         '
  375.         ' Redisplay the grid in the area that was magnified if the Grid option
  376.         ' is currently selected.
  377.         '
  378.         If editor.Menu_ViewSelection(MID_GRID).Checked Then Display_Grid (editor.Pic_Edit.hDC), X1, Y1, X2, Y2
  379.     Else
  380.         '
  381.         R = StretchBlt(editor.Pic_EditTemp.hDC, DestX, DestY, DestWidth, DestHeight, editor.Pic_Icons(CurrentIcon).hDC, X1, Y1, SrcWidth, SrcHeight, SRCCOPY)
  382.         '
  383.         ' Redisplay the grid in the area that was magnified if the Grid option
  384.         ' is currently selected.
  385.         '
  386.         If editor.Menu_ViewSelection(MID_GRID).Checked Then Display_Grid (editor.Pic_EditTemp.hDC), X1, Y1, X2, Y2
  387.         R = BitBlt(editor.Pic_Edit.hDC, DestX, DestY, DestWidth, DestHeight, editor.Pic_EditTemp.hDC, DestX, DestY, SRCCOPY)
  388.     End If
  389.  
  390.     ' Check if there is an active selection in the Editing area.  If so,
  391.     ' we must also redisplay the contents of the selection since the above
  392.     ' StretchBlt() operation may have entirely or partially covered up
  393.     ' the selection.
  394.     '
  395.     If MovingSelection Then
  396.         '
  397.         ' Calculate the width and height values of the source bitmap
  398.         ' containing the selection.  Always maintained in the global values
  399.         ' X1SelectFrom, Y1SelectFrom, X2SelectFrom, and Y2SelectFrom
  400.         '
  401.         SrcWidth = X2SelectFrom - X1SelectFrom
  402.         SrcHeight = Y2SelectFrom - Y1SelectFrom
  403.         
  404.         ' Calculate the destinations width and height of the area to be magnified.
  405.         '
  406.         DestWidth = SrcWidth * PixelSize
  407.         DestHeight = SrcHeight * PixelSize
  408.  
  409.         ' Determine type of Selection: Opaque, or Not Opaque.
  410.         '
  411.         If Opaque Then
  412.             '
  413.             ' Opaque selection: Magnify the selection bitmap including any Screen
  414.             ' or Inverse Screen attributes
  415.             '
  416.             R = StretchBlt(editor.Pic_Edit.hDC, X1Region, Y1Region, DestWidth, DestHeight, editor.Pic_Work.hDC, X1SelectFrom, Y1SelectFrom, SrcWidth, SrcHeight, SRCCOPY)
  417.         Else
  418.             ' None Opaque Selection: Magnify the selection bitmap but do not include
  419.             ' any Screen or Inverse Screen attributes.
  420.             '
  421.             R = StretchBlt(editor.Pic_Edit.hDC, X1Region, Y1Region, DestWidth, DestHeight, editor.Pic_TempMask.hDC, X1SelectFrom, Y1SelectFrom, SrcWidth, SrcHeight, SRCAND)
  422.             R = StretchBlt(editor.Pic_Edit.hDC, X1Region, Y1Region, DestWidth, DestHeight, editor.Pic_TempImage.hDC, X1SelectFrom, Y1SelectFrom, SrcWidth, SrcHeight, SRCINVERT)
  423.         End If
  424.     End If
  425.   
  426.     ' Redisplay the selection rectangle if currently making a selection
  427.     '
  428.     If Selecting Then Draw_Selection_Rectangle
  429.  
  430. End Sub
  431.  
  432. ' A Sub Main is used instead of a startup form to allow the user
  433. ' to startup either the Editor or Viewer as the main form.  The
  434. ' Editor is the Default main form, however starting IconWorks
  435. ' with a command line of "v" or "V" will start IconWorks with
  436. ' the Viewer as the main form.
  437. '
  438. Sub Main ()
  439.   
  440.     ' Check video mode.  If less than EGA, terminate Iconworks
  441.     '
  442.     If Screen.Height < EGA_HEIGHT Then
  443.         MsgBox "IconWorks requires EGA or Better.", 16, "IconWorks"
  444.         End
  445.     Else
  446.         ' Since you cannot assign values like TAB, CR, and LF to string
  447.         ' constants, the values of TAB and CRLF which are used frequently
  448.         ' thoughout IconWorks when displaying messages, these values are
  449.         ' are assigned to the global string values of A_TAB and CRLF
  450.         '
  451.         A_TAB = Chr$(9)
  452.         CRLF = Chr$(13) + Chr$(10)
  453.  
  454.         If Not Help_File_In_Path() Then
  455.             Text = "ICONWRKS.HLP not found in your path." + CRLF + CRLF
  456.             Text = Text + "Windows searches your PATH environment variable for help files, "
  457.             Text = Text + "so you need to copy ICONWRKS.HLP to a directory included in your "
  458.             Text = Text + "PATH if you wish to obtain help while running IconWorks."
  459.             MsgBox Text, 48, "IconWorks help not available"
  460.         End If
  461.         
  462.         ' Determine which form to use as main form, Editor) or the Viewer
  463.         '
  464.         If (Command$ = "") Or (UCase$(Left$(Command$, 1)) <> "V") Then
  465.             '
  466.             ' Editor is main form
  467.             '
  468.             MainForm = ICONWORKS_EDITOR
  469.             editor.Show
  470.         Else
  471.             ' Viewer is main form
  472.             '
  473.             MainForm = ICONWORKS_VIEWER
  474.             Viewer.Show
  475.         End If
  476.     End If
  477.  
  478. End Sub
  479.  
  480. ' Determines if an Icon has been modified since it was saved last, and
  481. ' prompts the user if so.
  482. '
  483. Function Ok_To_Discard_Changes ()
  484.  
  485.     Text = ""
  486.     Ok_To_Discard_Changes = True
  487.  
  488.     ' Check if Icon has changed since it was last saved.
  489.     '
  490.     If IconInfo(CurrentIcon).Changed Then
  491.         '
  492.         ' Inform user icon has been modifyied.
  493.         '
  494.         Text = Text + "Icon:" + A_TAB + "#" + Format$(CurrentIcon + 1) + CRLF
  495.         Text = Text + "Name:" + A_TAB + IconInfo(CurrentIcon).FileName + CRLF
  496.         Text = Text + "Path:" + A_TAB + IconInfo(CurrentIcon).FullPath + CRLF + CRLF
  497.         Text = Text + "Discard changes?"
  498.         Ok_To_Discard_Changes = MsgBox(Text, 36, "ICON HAS CHANGED") = MBYES
  499.     End If
  500.  
  501. End Function
  502.  
  503. ' Removes various menu items from the System menu of the specified Form.
  504. '
  505. Sub Remove_Items_From_Sysmenu (A_Form As Form)
  506.  
  507.     ' Obtain the handle to the forms System menu
  508.     '
  509.     HSysMenu = GetSystemMenu(A_Form.hWnd, 0)
  510.   
  511.     ' Remove all but the MOVE and CLOSE options.  The menu items
  512.     ' must be removed starting with the last menu item.
  513.     '
  514.     R = RemoveMenu(HSysMenu, 8, MF_BYPOSITION) 'Switch to
  515.     R = RemoveMenu(HSysMenu, 7, MF_BYPOSITION) 'Separator
  516.     R = RemoveMenu(HSysMenu, 5, MF_BYPOSITION) 'Separator
  517.  
  518. End Sub
  519.  
  520. ' The rectanglular Region which is always defined by the global
  521. ' variables X1Region, Y1Region, X2Region, and Y2Region, is the
  522. ' basis for most of the tools in the toolpalette, and is frequently
  523. ' scaled from the scale of the Editing area down to the scale of
  524. ' the actual Icon, and in the reverse direction.  This routine
  525. ' performs the neccessary scaling, in either direction based on
  526. ' the value of *ToIcon*.
  527. '
  528. Sub Scale_Region (ToIcon, X1, Y1, X2, Y2, CheckX1Y1)
  529.   
  530.     ' Determine which direction to scale
  531.     '
  532.     If ToIcon Then
  533.         '
  534.         ' Scale Global variables down to and Icon
  535.         '
  536.         X1 = X1Region \ PixelSize
  537.         Y1 = Y1Region \ PixelSize
  538.         X2 = X2Region \ PixelSize
  539.         Y2 = Y2Region \ PixelSize
  540.     
  541.         ' If requested, ensure X1 and Y1 refer to upper left corner
  542.         ' and X2 and Y2 refer to the lower right corner of the Region.
  543.         '
  544.         If CheckX1Y1 Then
  545.             If X1 > X2 Then Swap_Values X1, X2
  546.             If Y1 > Y2 Then Swap_Values Y1, Y2
  547.         End If
  548.     Else
  549.         ' Scale the values X1, Y1, X2, Y2 upto the Editing
  550.         ' area and assign to global variables
  551.         '
  552.         X1Region = X1 * PixelSize
  553.         Y1Region = Y1 * PixelSize
  554.         X2Region = X2 * PixelSize
  555.         Y2Region = Y2 * PixelSize
  556.     End If
  557.   
  558.  
  559. End Sub
  560.  
  561. ' When a new Icon from one of the 6 displayed within the StatusArea is selected
  562. ' or if a new icon is selected from the viewer to be edited, this routine is
  563. ' called to take care of the visual changes within the StatusArea.
  564. '
  565. Sub Select_New_Icon ()
  566.     
  567.     Selecting = False
  568.     MovingSelection = False
  569.  
  570.     HighLight_Current_Icon
  571.  
  572.     Extract_Image_And_Mask editor.Pic_Icons(CurrentIcon)
  573.       
  574.     ' Set the Undo Icon to the newly selected Icon.
  575.     '
  576.     Update_Icon editor.Pic_Undo
  577.  
  578.     ' Display the icon in the editing area
  579.     '
  580.     Magnify_Icon 0, 0, 31, 31
  581.  
  582.     ' Display the Filename of the selected icon in the Editor's Titlebar
  583.     '
  584.     editor.Caption = "IconWorks Editor: " + Format$(CurrentIcon + 1) + " - " + IconInfo(CurrentIcon).FileName
  585.  
  586. End Sub
  587.  
  588. ' Since the Swap statement is not supported by Visual Basic, this
  589. ' routine is used to perform the task of swapping two integer values.
  590. '
  591. Sub Swap_Values (Param1, Param2)
  592.  
  593.     temp = Param1
  594.     Param1 = Param2
  595.     Param2 = temp
  596.  
  597. End Sub
  598.  
  599. ' This routine is used by the SaveFileDlg and the Viewer to update the
  600. ' filespec displayed in the FileName TextBox whenever the forms Directory
  601. ' ListBox control is Single Clicked.  Since a Single click does not
  602. ' actually make a selection, this routine is called in response to a
  603. ' single click to display what would be the result if a double click
  604. ' is performed or if Enter is pressed.
  605. '
  606. Sub UpDate_FileSpec (A_Form As Form)
  607. Dim SelPath As String, CurPath As String, Slash As String
  608.  
  609.     CurPath = A_Form.Lbl_CurrentDirectory.Caption
  610.     SelPath = A_Form.Dir_DirectoryList.List(A_Form.Dir_DirectoryList.ListIndex)
  611.  
  612.     Select Case A_Form.Dir_DirectoryList.ListIndex
  613.         
  614.         Case Is >= 0
  615.             '
  616.             ' A subdirectory from the Current directory was selected
  617.             '
  618.             I = Right$(CurPath, 1) <> "\"
  619.             A_Form.Txt_FileName.Text = Right$(SelPath, Len(SelPath) - Len(CurPath) + I) + "\" + A_Form.File_FileList.Pattern
  620.         
  621.         Case Is = -1
  622.             '
  623.             ' The current directory was selected
  624.             '
  625.             A_Form.Txt_FileName.Text = A_Form.File_FileList.Pattern
  626.         
  627.         Case Is < -1
  628.             '
  629.             ' A parent directory of the Current directory was selected
  630.             '
  631.             SelPath = Right$(SelPath, Len(SelPath) - 2)
  632.             If Len(SelPath) > 1 Then Slash = "\"
  633.             A_Form.Txt_FileName.Text = SelPath + Slash + A_Form.File_FileList.Pattern
  634.     
  635.     End Select
  636.  
  637. End Sub
  638.  
  639. ' We do not actually modify the Icon directly, but modify the Mask and Image
  640. ' bitmaps that make up the Icon. So these bitmaps must be copied over the icons
  641. ' Mask and Image bitmaps after each edit to reflect the change in the actual
  642. ' icon displayed in the StatusArea.
  643. '
  644. Sub Update_Icon (Pic_Ctrl As Control)
  645. Dim Lpicon As Long
  646.   
  647.     ' Convert the 4-Plane Mask Bitmap contained in the Picture Control to
  648.     ' a 1-Plane Bitmap.
  649.     '
  650.     R = BitBlt(MonoHdc, 0, 0, 32, 32, editor.Pic_Mask.hDC, 0, 0, SRCCOPY)
  651.  
  652.     ' Obtain a far Pointer to the actual Icons information and Bitmaps
  653.     ' and Lock this information so Windows will not move it.
  654.     '
  655.     Lpicon = GlobalLock(Pic_Ctrl.Picture)
  656.  
  657.     ' Replace the Icons Mask Bitmap with the new Mask Bitmap.
  658.     '
  659.     R = GetBitmapBits(MonoHbm, 128, Lpicon + 12)
  660.  
  661.     ' Replace the Icons Image Bitmap with the new Image Bitmap.
  662.     '
  663.     R = GetBitmapBits(editor.Pic_Image.Image, ImageSize, Lpicon + 12 + 128)
  664.  
  665.     ' Unlock the Icons memory so Windows is free to move it if neccessary
  666.     '
  667.     R = GlobalUnlock(Pic_Ctrl.Picture)
  668.  
  669.     ' Since VB is unaware of any modifications we make to the Icon using
  670.     ' any API routines, it does not know to redisplay the Icon, so we
  671.     ' must force it to display the new icon.
  672.     '
  673.     Pic_Ctrl.Cls
  674.  
  675.     ' Set Changed Flag to TRUE since it has been modified.
  676.     '
  677.     If Pic_Ctrl.Tag <> editor.Pic_Undo.Tag Then IconInfo(CurrentIcon).Changed = True
  678.  
  679. End Sub
  680.  
  681. ' When either the Editors ColorPalette or the ColorPalette Forms
  682. ' Color Palette is clicked, this routine is called to set the selected
  683. ' color into the Mouse colors, and invoke the ColorPalette Form in
  684. ' the case of a Double Click event on the Editors Color Palette.
  685. '
  686. Sub Update_Mouse_Colors (Button, X As Single, Y As Single)
  687. Dim color As Long, SolidColor As Long
  688.  
  689.     ' The ColorPalettes are a single picture control, so we must calculate
  690.     ' the color selected based on the coordinates of the mouse.
  691.     '
  692.     ColorIndex = Fix(X) + Fix(Y) * 16
  693.  
  694.     ' Obtain color from color array
  695.     '
  696.     color = Colors(ColorIndex)
  697.  
  698.     ' VB only supports 16 color mode, so we must obtain the nearest Solid
  699.     ' color to the selected color since the Screen and Inverse colors cannot
  700.     ' be set to dithered colors.
  701.     '
  702.     SolidColor = GetNearestColor(editor.hDC, color)
  703.  
  704.     If DoubleClicked Then
  705.         '
  706.         ' The Editors ColorPalette was Double Clicked, so reset the Flag
  707.         ' and invoke the ColorPalette Form.
  708.         '
  709.         DoubleClicked = False
  710.         ColorPalette.Show
  711.  
  712.         ' The ColorPalette Forms initialization is done within the
  713.         ' GotFocus Event for its ColorPalette Picture control, so we
  714.         ' must give that Picture Control the focus.
  715.         '
  716.         ColorPalette.Pic_ColorPalette.SetFocus
  717.  
  718.     ElseIf editor.Opt_Mouse(SCREEN_COLORS).Value And (color <> SolidColor) Then
  719.         '
  720.         ' An attempt to select a Dithered color into the Screen or Inverse
  721.         ' colors was made, so Prompt the user and do not allow the selection
  722.         '
  723.         MsgBox "Screen and Inverse colors can only be set to solid colors", 16, "Error"
  724.     Else
  725.         ' Obtain the the index of the corresponding mouse Color:
  726.         '   0 - Left Mouse Color
  727.         '   1 - Right Mouse Color
  728.         '   2 - Screen Color
  729.         '   3 - Inverse Screen Color
  730.         '
  731.         Index = editor.Opt_Mouse(SCREEN_COLORS).Value * (-2) + Button - 1
  732.  
  733.         ' Replace the Mouse color with the new color
  734.         '
  735.         MouseColors(Index) = Colors(ColorIndex)
  736.  
  737.         ' Changing either the Screen Color or Inverse Screen Color also
  738.         ' changes the other so if either the Screen or Inverse color was
  739.         ' changed, we must change the other to its inverse.
  740.         '
  741.         If Index >= 2 Then
  742.             editor.Pic_Icons(0).PSet (1, 1), MouseColors(Index)
  743.             MouseColors(Abs(Index - 5)) = editor.Pic_Icons(0).Point(1, 1)
  744.             editor.Pic_Icons(0).Cls
  745.         End If
  746.     
  747.         If editor.Opt_Mouse(SCREEN_COLORS).Value Then
  748.             '
  749.             ' The Screen or Inverse Screen color was changed, so we must change
  750.             ' the BackColor of all 6 icons in the StatusArea and the Undo Icon to
  751.             ' the new Screen Color and then redisplay the selected Icon in the
  752.             ' Editing area.
  753.             '
  754.             HighLight_Current_Icon
  755.             For I = 0 To 5
  756.                 editor.Pic_Icons(I).BackColor = MouseColors(2)
  757.             Next
  758.             editor.Pic_Undo.BackColor = MouseColors(2)
  759.             Magnify_Icon 0, 0, 31, 31
  760.         End If
  761.  
  762.     End If
  763.  
  764.     ' Diplay the New Mouse colors at the Bottom of the StatusArea
  765.     '
  766.     Display_Mouse_Colors
  767.  
  768. End Sub
  769.  
  770. ' Selecting a new drive from the list of a Drive controls drop
  771. ' down list does not generate an error if the drive is not ready,
  772. ' so when a new drive is selected, we determine if it is ready
  773. ' or not.  This routine validates the selected drive and is use
  774. ' by both the SaveFileDlg's and Viewers's Drive control
  775. '
  776. Sub Validate_And_Change_Drives (A_Form As Form)
  777.     
  778.     On Error Resume Next
  779.     Err = False
  780.  
  781.     ' Invoking the Dir$() function with the selected drive will generate
  782.     ' an error if the drive is not ready.  We don't care about the return
  783.     ' value, we just care if an error is generated or not.
  784.     '
  785.     Dummy$ = Dir$(Left$(A_Form.Drv_DriveList.Drive, 2))
  786.  
  787.     If Err Then
  788.         '
  789.         ' The drive was not ready, so prompt the user
  790.         '
  791.         Beep
  792.         MsgBox Error$(Err), 16, "IconWorks - ERROR: " + Format$(Err)
  793.  
  794.         ' Reset the Drive Control back to its previously selected drive
  795.         '
  796.         A_Form.Drv_DriveList.Drive = Left$(A_Form.Dir_DirectoryList.Path, 2)
  797.     Else
  798.         ' The drive is ready, so change to that drive
  799.         '
  800.         ChDrive A_Form.Drv_DriveList.Drive
  801.         A_Form.Dir_DirectoryList.Path = CurDir$
  802.     End If
  803.   
  804.     On Error GoTo 0
  805.  
  806. End Sub
  807.  
  808. ' When a filespec is entered into either the Viewer's Filename
  809. ' TextBox or the SaveFileDlg's Filename TextBox, this routine is
  810. ' called to validate the FileSpec.  The name and path, if one is
  811. ' given, is validated.  If a valid FileSpec to an actual file is
  812. ' entered and the file does not exist, the return value depends
  813. ' on which Form called this routine, since a if called from the
  814. ' SaveFileDlg a "File Not Found" error is generated but that is
  815. ' OK since a file does not have to exist to write to it.  However,
  816. ' if called from the Viewer, the same error will be generated but
  817. ' in this case the file must exists since the Viewer is wants to
  818. ' open the file for editing.
  819. '
  820. Function Validate_FileSpec (AForm As Form, MustExist)
  821. Dim temp As String
  822.  
  823.     ' Enable error trapping
  824.     '
  825.     On Error GoTo ErrorInSpec
  826.  
  827.     Validate_FileSpec = False
  828.  
  829.     ' Check for valid DOS Path and Filenames.
  830.     '
  831.     temp = Dir$(AForm.Txt_FileName.Text)
  832.  
  833.     ' The following statement does alot.  It the FileSpec contains
  834.     ' a Path, the FileSpec will be parsed and the Path will be assign
  835.     ' to the File ListBox's Path property.  If the FileSpec contains
  836.     ' Wild card characters, it will be assign to the File ListBox's
  837.     ' pattern property.  If the FileSpec contains a valid file name
  838.     ' and the file exists, a Double Click event will automatically be
  839.     ' generated for the File ListBox.  If the File does not exist,
  840.     ' a "File Not Found" error will be generated which we trap.
  841.     '
  842.     AForm.File_FileList.Filename = AForm.Txt_FileName.Text
  843.   
  844. Exit_The_Function:
  845.  
  846.     ' Turn off error trapping and exit the function
  847.     '
  848.     On Error GoTo 0
  849.     Exit Function
  850.  
  851. ErrorInSpec:
  852.     If (Err <> FILE_NOT_FOUND) Or ((Err = FILE_NOT_FOUND) And MustExist) Then
  853.         '
  854.         ' An error other than "File Not Found" occured, or the error
  855.         ' "File Not Found" occured and this Function was invoked from
  856.         ' the Viewer which requires the file to exist.
  857.         '
  858.         Beep
  859.         MsgBox Error$(Err), 16, "IconWorks - ERROR: " + Format$(Err)
  860.     Else
  861.         ' The FileSpec entered contain no errors other than maybe
  862.         ' "File Not Found".
  863.         '
  864.         If Err = FILE_NOT_FOUND Then
  865.             ' A Valid filename was entered in the SaveFileDlg which did not exist
  866.             ' so the File Control did not parse the FileSpec for us.  Since the
  867.             ' FileSpec could contain a path specification, force File control
  868.             ' to parse the Filename string for us by changing last character to
  869.             ' an asterisk "*" and assign the modified FileSpec to the File Controls
  870.             ' FileName property.  The asterisk "*" makes the Filename appear as a
  871.             ' FileSpec rather than a Filename to the File ListBox and it will parse
  872.             ' it for us whether there are any matching files or not.  After it has
  873.             ' been parsed, we change the "*" back to its previous value.
  874.             '
  875.             temp = Right$(AForm.Txt_FileName.Text, 1)
  876.             AForm.File_FileList.Filename = Left$(AForm.Txt_FileName.Text, Len(AForm.Txt_FileName.Text) - 1) + "*"
  877.             AForm.Txt_FileName.Text = Left$(AForm.File_FileList.Pattern, Len(AForm.File_FileList.Pattern) - 1) + temp
  878.             
  879.             ' This checks to see that that file name that has been parsed
  880.             ' is a valid DOS file name
  881.  
  882.              PeriodPos = InStr(1, AForm.Txt_FileName.Text, ".")
  883.              If PeriodPos <> 0 Then
  884.                 LeftofPeriod$ = Left$(AForm.Txt_FileName.Text, PeriodPos - 1)
  885.              Else
  886.                LeftofPeriod$ = AForm.Txt_FileName.Text
  887.              End If
  888.              If Len(AForm.Txt_FileName.Text) > 8 Then
  889.                      Resume Exit_The_Function
  890.             End If
  891.             Else
  892.         End If
  893.         Validate_FileSpec = True
  894.     End If
  895.     Resume Exit_The_Function
  896.  
  897. End Function
  898.  
  899. ' Saves the current icon to disk, and updates the Icon menu and
  900. ' Editors title bar with the new Icons filename.
  901. '
  902. Sub Write_Icon_To_File (FullPath As String, FileName As String)
  903.   
  904.     ' Save new Filename and Path information for the Icon
  905.     '
  906.     IconInfo(CurrentIcon).FileName = FileName
  907.     IconInfo(CurrentIcon).FullPath = FullPath
  908.     IconInfo(CurrentIcon).Changed = False
  909.  
  910.     ' Display the Icons Filename and Path in the Editors Icon menu
  911.     '
  912.     editor.Menu_IconsSelection(CurrentIcon).Caption = "&" + Format$(CurrentIcon + 1) + " - [" + FullPath + "]" + A_TAB + FileName
  913.  
  914.     ' Display the Icons Filename in the Editors TitleBar
  915.     '
  916.     editor.Caption = "IconWorks Editor: " + Format$(CurrentIcon + 1) + " - " + FileName
  917.  
  918.     ' Save the Icon to the specified File in the Specified Directory
  919.     '
  920.     If Right$(FullPath, 1) <> "\" Then FullPath = FullPath + "\"
  921.     SavePicture editor.Pic_Icons(CurrentIcon).Picture, FullPath + FileName
  922.  
  923. End Sub
  924.  
  925.